layui.use(['table', 'admin', 'ax', 'laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;

    /**
     * 商品表管理
     */
    var BasicGoods = {
        tableId: "basicGoodsTable"
    };

    /**
     * 初始化表格的列
     */
    BasicGoods.initColumn = function () {
        return [[
            {field: 'id', hide: true, title: '主键'},
            {field: 'goodsCustomerName', title: '客户',width:130, style:'background-color: #ecf5ff;font-weight: 600;'},
            {field: 'goodsName', sort: true, title: '商品名称',width:200, style:'font-weight: 600;'},
            {field: 'goodsNumber', sort: true, title: '商品编号',width:130, style:'font-weight: 600;'},
            {field: 'goodsSupportvolume', title: '每托存量', style:'font-weight: 600;'},
            {field: 'goodsVolume', title: '体积（M3）'},
            {field: 'goodsWeight', title: '重量'},
            {field: 'goodsCharging', title: '计费指定价'},
            {field: 'goodsPacking', title: '包装'},
            {field: 'goodsBigtype', title: '商品大类'},
            {field: 'goodsType', title: '商品类别'},
            {field: 'goodsUnit', title: '单位'},
            {field: 'goodsSpecs', title: '规格'},
            {align: 'center', width:70, toolbar: '#tableBar', title: '操作', fixed:'right'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    BasicGoods.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(BasicGoods.tableId, {
            where: queryData, page: {curr: 1},
            done:function () {
            }
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + BasicGoods.tableId,
        url: Feng.ctxPath + '/hxBasicGoods/ChoiceGoods?goodsCustomerId='+Feng.getUrlParam("goodsCustomerId"),
        page: true,
        limit: 30,
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: BasicGoods.initColumn()
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        BasicGoods.search();
    });

    //回填商品数据
    function confirm(data){
        parent.StorageStockInfoDlg.data.goodsName = data.goodsName;//商品名称
        parent.StorageStockInfoDlg.data.goodsId = data.id;//商品id
        parent.StorageStockInfoDlg.data.goodsNumber = data.goodsNumber;//商品编号
        /*parent.OrderPutDetailedInfoDlg.data.detailedRebubbles = data.goodsHeavybubble;//重泡货
        parent.OrderPutDetailedInfoDlg.data.detailedPacking = data.goodsPacking;//商品包装
        parent.OrderPutDetailedInfoDlg.data.detailedLargeclass = data.goodsBigtype;//商品大类
        parent.OrderPutDetailedInfoDlg.data.detailedGoodstype = data.goodsType;//商品类别
        parent.OrderPutDetailedInfoDlg.data.detailedPutcondition = data.goodsCondition;//保管条件
        parent.OrderPutDetailedInfoDlg.data.detailedPiecenum = 1;//件装量
        parent.OrderPutDetailedInfoDlg.data.goodsWeight = data.goodsWeight;//重量
        parent.OrderPutDetailedInfoDlg.data.goodsVolume = data.goodsVolume;//体积
        parent.OrderPutDetailedInfoDlg.data.goodsCharging = data.goodsCharging;//计费指定价*/
        var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    }

    // 双击行事件
    table.on('rowDouble(' + BasicGoods.tableId + ')', function (obj) {
        var data = obj.data;
        confirm(data);
    });

    // 工具条点击事件
    table.on('tool(' + BasicGoods.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'confirm') {
            confirm(data);
        }
    });
});
